package com.firefly.web.controller.admin.cms;

import com.firefly.dao.dto.cms.ArticleDto;
import com.firefly.dao.dto.cms.ArticleSearchDto;
import com.firefly.web.controller.admin.ConsoleApiRestController;
import com.firefly.dao.dto.CommonDto;
import com.firefly.dao.vo.CommonListVo;
import com.firefly.dao.vo.cms.ArticleVo;
import com.firefly.service.command.cms.ArticleCommand;
import com.firefly.service.query.cms.ArticleQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

/**
 * (Articles)表控制层
 *
 * @author makejava
 * @since 2022-08-02 08:57:42
 */
@ConsoleApiRestController("/article")
public class ArticleController {
    private final ArticleQuery articleQuery;
    private final ArticleCommand articleCommand;

    @Autowired
    public ArticleController(ArticleQuery articleQuery, ArticleCommand articleCommand) {
        this.articleQuery = articleQuery;
        this.articleCommand = articleCommand;
    }

    @GetMapping("/list")
    public CommonListVo getAll(ArticleSearchDto request) {
        return articleQuery.getList(request);
    }

    @GetMapping("/detail")
    public ArticleVo getDetail(@Validated(CommonDto.showDetail.class) CommonDto request) {
        return articleQuery.getDetail(request);
    }

    @PostMapping("/create")
    public Boolean postCreate(@Validated(ArticleDto.create.class) ArticleDto request) {
        return articleCommand.create(request);
    }

    @PostMapping("/update")
    public Boolean postUpdate(@Validated(ArticleDto.update.class) ArticleDto request) {
        return articleCommand.update(request);
    }

    @PostMapping("/remove")
    public Boolean postRemove(@Validated(CommonDto.removeMultiple.class) CommonDto request) {
        return articleCommand.remove(request);
    }

}

